package net.destroyer.game.tetris.core.gamespace.util;

import javax.media.j3d.Appearance;
import javax.media.j3d.GeometryArray;
import javax.media.j3d.LineArray;
import javax.media.j3d.PolygonAttributes;
import javax.media.j3d.Shape3D;
import javax.vecmath.Point3f;

public class Hash extends Shape3D {
	public Hash(int width, int height) {
		super();
		float minx = -(width / 2f);
		float maxx = (width / 2f);
		float miny = -(height / 2f);
		float maxy = (height / 2f);
		
		GeometryArray la = new LineArray(((width+1)*2+(height+1)*2), GeometryArray.COORDINATES);
		int ent = 0;
		for (int i = 0; i < width+1; i++) {
			la.setCoordinate(ent++, new Point3f(minx+i,miny,0));
			la.setCoordinate(ent++, new Point3f(minx+i,maxy,0));
		}
		for (int i = 0; i < height+1; i++) {
			la.setCoordinate(ent++, new Point3f(minx,miny+i,0));
			la.setCoordinate(ent++, new Point3f(maxx,miny+i,0));
		}
		this.setGeometry(la);
	
		PolygonAttributes pa = new PolygonAttributes();
		pa.setCullFace(PolygonAttributes.CULL_NONE);
		pa.setBackFaceNormalFlip(true);
		pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
		Appearance appear = new Appearance();
		appear.setPolygonAttributes(pa);
		this.setAppearance(appear);
	}
}
